﻿#region header

//  ***************************************************************************
// *                                LICENSE
//  ***************************************************************************
//  * "Haplous" .NET Simple 2D Game Framework
//  * 
//  * Copyright © Jonathan Evans 2014-2014
//  * 
//  * This program is free software; you can redistribute it and/or
//  * modify it under the terms of the GNU General Public License
//  * as published by the Free Software Foundation; either version 2
//  * of the License, or (at your option) any later version.
//  * 
//  * This program is distributed in the hope that it will be useful,
//  * but WITHOUT ANY WARRANTY; without even the implied warranty of
//  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  * GNU General Public License for more details.
//  * 
//  * You should have received a copy of the GNU General Public License
//  * along with this program; if not, write to the Free Software
//  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//  * 
//  ***************************************************************************
//  * 
//  * Contact: opencollar@googlemail.com
//  * 
//  * Website: http://haplous.codeplex.com/
//  *
//  * NuGet:   http://www.nuget.org/packages/haplous/
//  *
//  * File:    Haplous/Haplous/Graphic.cs
//  *
//  ***************************************************************************

#endregion

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

using Haplous.Core;

using JetBrains.Annotations;

namespace Haplous
{
    /// <summary>
    ///     The basic class for all visual elements in a game.
    /// </summary>
    [SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
    [DebuggerDisplay("Graphic: Name={Name}")]
    public abstract class Graphic : ElementBase, IGraphic
    {
        /// <summary>
        ///     The source of the picture to display on this element.
        /// </summary>
        [NotNull]
        private readonly ModeProperty<PictureSource> _pictureSource;

        /// <summary>
        ///     Defines the way in which this element and the picture on it are rendered.
        /// </summary>
        [NotNull]
        private readonly ModeProperty<Visualization> _visualization;

        /// <summary>
        ///     Initializes a new instance of the <see cref="ElementBase" /> class.
        /// </summary>
        /// <param name="game">
        ///     The game to which the class belongs.  The <paramref name="game" /> must not be
        ///     <see langword="null" />.
        /// </param>
        internal Graphic([NotNull] Game game) : base(game)
        {
            _pictureSource = new ModeProperty<PictureSource>(game, "PictureSource");
            _visualization = new ModeProperty<Visualization>(game, "Visualization");
        }

        /// <summary>
        ///     Copies the property values for the element in one mode to another mode.
        /// </summary>
        /// <param name="source">The source mode of the property values.</param>
        /// <param name="destination">The destination mode of the property values.</param>
        /// <param name="excludedProperties">A list of the names of the properties to exclude from the copy.</param>
        public override void CopyModeProperties(Mode source, Mode destination, IEnumerable<string> excludedProperties)
        {
            base.CopyModeProperties(source, destination, excludedProperties);

            if((excludedProperties == null) || !excludedProperties.Contains("PictureSource"))
                _pictureSource.CopyModeProperties(source, destination);
            if((excludedProperties == null) || !excludedProperties.Contains("Visualization"))
                _visualization.CopyModeProperties(source, destination);
        }

        /// <summary>
        ///     Defines the way in which this element and the picture on it are rendered.
        /// </summary>
        [NotNull]
        public Visualization Visualization
        {
            get { return _visualization.Value; }
        }

        /// <summary>
        ///     The source of the picture to display on this element.
        /// </summary>
        [NotNull]
        public PictureSource PictureSource
        {
            get { return _pictureSource.Value; }
        }
    }
}